package com.dq.controller.api.subscribe;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dq.domain.service.ServiceProject;
import com.dq.exception.customException.AdminException;
import com.dq.service.AllService;
import com.dq.vo.ListDataVo;
import com.dq.vo.Vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author luchangtong
 * @Date 2020/4/9 15:29
 */
@Api(description = "服务项目管理")
@RestController
@RequestMapping("api/serviceProject/")
public class ApiServiceProjectController extends AllService {
    @ApiOperation("所有服务项目列表")
    @GetMapping("listAll")
    public Vo listAll()throws AdminException{
        List<ServiceProject> serviceProjects = serviceProjectRepository.findByDeletedFalse();

        JSONArray array = new JSONArray();
        serviceProjects.forEach(serviceProject -> {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("id",serviceProject.getId());
            jsonObject.put("name",serviceProject.getProjectName());
            jsonObject.put("data", serviceProject.toVO());
            array.add(jsonObject);
        });
        return new ListDataVo(array,serviceProjects.size());
    }
}
